<?php
//用于写Article各个网站统一的函数
// include_once('public_article_extend_one.php');
include_once 'public_function.php';
class PublicArticle  extends PublicFunction  {
	
	function __construct($arr = NULL){
		
	}
	
	//根据网站类型得到广告表信息
	function getAdTablesData($web_type,$web_position = 'index') {
		
		$webType = empty($web_type) ? 'wondershare' : strtolower(trim(htmlspecialchars($web_type)));
		$adWeb = 0;//网站标记
		$positionType = 0 ;//广告位类型
		$positionId  = 0 ;//广告位主键
		$catId = 0;//分类ID
		
		//网站类型
		switch ($webType) {
			
			case 'wondershare':
				
				break; 
				
			case 'iskysoft':
				
				$adWeb = 8;
				if ($web_position == 'index') {
					$positionType = 2;
					$positionId = 33;
				} else if ($web_position == 'article_left') {
					$positionType = 1;
					$positionId = 18;
				} else if($web_position == 'article_top') {
					$positionType = 1;
					$positionId = 39;
				} else if($web_position == 'subject_top') {
					$positionType = 1;
					$positionId = 39;
				} else if($web_position == 'subject_left') {
					$positionType = 1;
					$positionId = 18;
				} else if($web_position == 'tag_left') {
					$positionType = 4;
					$positionId = 19;
				} else if($web_position == 'tag_top') {
					$positionType = 4;
					$positionId = 40;
				}
				break; 
		
			case 'iskysoft_jp':	//	----------------------------------pkjueying
			
				$adWeb = 200;
				if ($web_position == 'index') {	//resource top
					$positionType = 2;
					$positionId = 58;
				} else if ($web_position == 'article_left') {
					$positionType = 1;
					$positionId = 56;
				} else if($web_position == 'article_top') {
					$positionType = 1;
					$positionId = 57;
				} else if($web_position == 'subject_top') {
					$positionType = 1;
					$positionId = 39;
				} else if($web_position == 'subject_left') {
					$positionType = 1;
					$positionId = 18;
				} else if($web_position == 'tag_left') {
					$positionType = 4;
					$positionId = 62;
				} else if($web_position == 'tag_top') {
					$positionType = 4;
					$positionId = 63;
				}
				break;
		}
		
		return array('webType' => $webType, 'adWeb' => $adWeb, 'positionType' => $positionType,
					 'positionId' => $positionId, 'catId' => $catId
		);
	}
	
	//根据网站类型得到相应的tag表，文章表，以及专题表信息
	function getWebTablesData($web_type) {
		
		$webType = empty($web_type) ? 'wondershare' : strtolower(trim(htmlspecialchars($web_type)));
		$WebFage = 0;//网站类型
		$temCatTable = '';//分类模板表名
		$temCatId = 0;//模板分类ID
		$temArtTable = '';//文章模板表名
		$temArtId = 0;//模板文章ID
		$temTagTable = '';//标签模板表名
		$temTagId = 0;//模板标签ID
		$urlRep = '';//url替换类型
		
		//网站类型
		switch ($webType) {
			
			case 'wondershare'://表示取最新
				
				break; 
				
			case 'iskysoft':
				$temCatTable = 'Table_72';
				$temCatId = 'Field_20690';
				$temCatName = 'Field_20692';
				$temArtTable = 'Table_71';
				$temArtId = 'Field_20681';
				$temArtTable_2 = 'Table_169';
				$temArtId_2 = 'Field_21843';
				$temTagTable = 'Table_73';
				$temTagId = 'Field_20698';
				$WebFage = 8;
				$urlType = 'iskysoft';
				break; 
				
			case 'daniusoft':
				$temCatTable = 'Table_212';
				$temCatId = 'Field_22201';
				$temCatName = 'Field_22202';
				$temArtTable = 'Table_211';
				$temArtId = 'Field_22196';
				$temArtTable_2 = '';
				$temArtId_2 = '';
				$temTagTable = 'Table_213';
				$temTagId = 'Field_22206';
				$WebFage = 15;
				$urlType = 'daniusoft';
				break; 
				
			case 'iskysoft_jp':					//------------------------------pkjueying
				$temCatTable = 'Table_273';  //网站文章专题模板
				$temCatId = 'Field_22453';	//专题ID
				$temCatName = 'Field_22454';	//专题名称
				$temArtTable = 'Table_275';  //网站文章模板
				$temArtId = 'Field_22562';	//文章ID
				$temArtTable_2 = 'Table_290';	//网站产品改文章模版
				$temArtId_2 = 'Field_22567';	//文章ID
				$temTagTable = 'Table_274';	//网站tag标签模版
				$temTagId = 'Field_22458';	//标签ID
				$WebFage = 200;
				$urlType = 'iskysoft.jp';
				break;
		}
		
		return array('temCatTable' => $temCatTable, 'temCatId' => $temCatId, 'temArtTable' => $temArtTable,
					 'temArtId' => $temArtId,'temTagTable' => $temTagTable, 'temTagId' => $temTagId, 
					 'WebFage' => $WebFage, 'urlType' => $urlType, 'temCatName' => $temCatName, 
					 'temArtTable_2' => $temArtTable_2, 'temArtId_2' => $temArtId_2);
	}
	
	//得到首页头部广告
	function getIndexTopAdInfo($get = array() ) {
		
		extract($this->getAdTablesData($get['web_type'], 'index'));//把数组分解成变量

		$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
				FROM ad_delivery, ad, ad_position 
				WHERE ad_delivery.position_id = $positionId AND ad_delivery.cat_id = $catId AND ad_delivery.position_type = $positionType 
					AND ad_delivery.ad_web = $adWeb AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1 ";
		$rows = $GLOBALS['db']->getOneRs($sql);

		return $rows;
	}
	
	//得到首页分类信息
	function getIndexCategoryInfo($get = array() ) {
	
		$web_date = $this->getWebTablesData($get['web_type']);//把数组分解成变量
		
		$sql = "SELECT cate.cat_title,cate.cat_id,cate.cat_thumb,cate.cat_image,tab.url,tab.{$web_date['temCatId']} 
				FROM category AS cate 
				LEFT JOIN {$web_date['temCatTable']}  AS tab ON cate.cat_id = tab.{$web_date['temCatId']}
				WHERE cate.is_delete = 0 AND cate.is_recommended=1 AND cate.cat_type = 1 AND cate.cat_web = '{$web_date['WebFage']}'  AND cate.cat_series = 3 
				ORDER BY cate.sort_order ASC,cate.add_time DESC LIMIT 6 ";
	
		return array('web_date' => $web_date, 'sql' => $sql);
	}
	
	//得到文章名称
	function getArticleName($get = array() ) {
		
		return $get['文章名称'];
	}
	
	//得到文章主分类
	function getArticleMainCategoryInfo($get = array() ) {
		
		if (empty($get['文章ID'])) {
			return '';
		} else {
			$arId = (int) $get['文章ID'];
		}

		$web_date = $this->getWebTablesData($get['web_type']);//把数组分解成变量
		$sql = "SELECT tab.{$web_date['temCatName']},tab.url 
				FROM topic_article ar 
				LEFT JOIN {$web_date['temCatTable']} tab ON ar.ar_cat_id = tab.{$web_date['temCatId']}
				WHERE ar.is_delete = 0 AND ar.ar_id = $arId ";
	
		$rows =  $GLOBALS['db']->getOneRs($sql);
		return array('web_date' => $web_date, 'rows' => $rows);

	}
	
	//得到文章副标题
	function getArticleSubtitle($get = array() ) {
		
		if (empty($get['文章ID'])) {
			return '';
		} else {
			$arId = $get['文章ID'];
		}
		
		$sql = "SELECT `ar_subtitle` 
				FROM topic_article 
				WHERE `is_delete`=0 AND `ar_id`= {$arId}";
		$ar_subtitle = $GLOBALS['db']->getOne($sql);
		
		if ($ar_subtitle){
			return $ar_subtitle;
		} else {
			return '';
		}
	}
	
	//得到文章发表时间
	function getArticlePubTime($get = array() ) {

		if (empty($get['文章ID'])) {
			return '';
		} else {
			$arId = (int) $get['文章ID'];
		}
		
		$sql = "SELECT `add_time` 
				FROM topic_article 
				WHERE `is_delete`=0 AND `ar_id`= {$arId} ";
		$add_time = $GLOBALS['db']->getOne($sql);
		
		if ($add_time) {
			$str =  substr(date("r",$add_time), 0, -5);
			return $str;
		} else {
		 	return '';
		}
	}
	
	//得到文章正文
	function getArticleContent($get = array() ) {
		
		if (empty($get['文章ID'])) {
			return '';
		} else {
			$arId = (int) $get['文章ID'];
		}
		
		$sql = "SELECT `ar_content` 
				FROM topic_article 
				WHERE `is_delete`=0 AND `ar_id` = {$arId}";
		$ar_content = $GLOBALS['db']->getOne($sql);
		
		if ($ar_content) {
			return $ar_content;
		} else {
		 	return '';
		}
	}
	
	//得到热门标签
	function getArticleHotTagInfo($get = array() ) {
	
		$web_date = $this->getWebTablesData($get['web_type']);

		$sql = "SELECT c.tag_name,t.url 
				FROM tag c 
				LEFT JOIN {$web_date['temTagTable']} t ON t.{$web_date['temTagId']} = c.tag_id 
				WHERE c.is_hot = 1 AND c.is_delete =0 AND c.tag_web = '{$web_date['WebFage']}'";
	
		return array('web_date' => $web_date, 'sql' => $sql);
	}

	//得到相关文章
	function getArticleRelatedInfo($get = array() ) {
		
		if (empty($get['文章ID'])) {
			return '';
		} else {
			$ar_id = (int) $get['文章ID'];
		}
		
		$web_date = $this->getWebTablesData($get['web_type']);
		
		$sql = "SELECT related_article 
				FROM topic_article 
				WHERE is_delete=0 AND web_type = {$web_date['WebFage']} AND `ar_id` = {$ar_id}";
		
		$related_article = $GLOBALS['db']->getOne($sql);
		
		return array('web_date' => $web_date, 'related_article' => $related_article);
	}
	
	//得到文章右侧广告
	function getArticleLeftAdInfo($get = array() ) {
		

		if (empty($get['文章ID'])) {
			return '';
		} else {
			$ar_id = (int) $get['文章ID'];
		}
		
		extract($this->getAdTablesData($get['web_type'], 'article_left'));//把数组分解成变量
		$sql = "SELECT `ar_cat_id` 
				FROM topic_article 
				WHERE `is_delete` = 0 AND `ar_id`= {$ar_id}";
		$catId = $GLOBALS['db']->getOne($sql);
		$rows = array();
		if (!empty($catId)) {
			
			$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
					FROM ad_delivery, ad, ad_position 
					WHERE ad_delivery.position_id = {$positionId} AND ad_delivery.cat_id = {$catId} AND ad_delivery.position_type = {$positionType} 
							AND ad_delivery.ad_web = {$adWeb} AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1";	
			$rows = $GLOBALS['db']->getOneRs($sql);
			

		}
		return $rows;
	}
	
	//得到文章头部广告
	function getArticleTopAdInfo($get = array() ) {
		
		if (empty($get['文章ID'])) {
			return '';
		} else {
			$ar_id = $get['文章ID'];
		}
		
		extract($this->getAdTablesData($get['web_type'],'article_top'));//把数组分解成变量
		$sql = "SELECT `ar_cat_id` 
				FROM topic_article 
				WHERE `is_delete`=0 AND `ar_id`= {$ar_id}";
		$catId = $GLOBALS['db']->getOne($sql);
		$rows = array();
		if (!empty($catId)) {
			
			$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
					FROM ad_delivery, ad, ad_position 
					WHERE ad_delivery.position_id = {$positionId} AND ad_delivery.cat_id = {$catId} AND ad_delivery.position_type = {$positionType} 
						AND ad_delivery.ad_web = {$adWeb} AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1";		
			$rows = $GLOBALS['db']->getOneRs($sql);
	
		}
		return $rows;
	}
	
	//得到文章评论
	function getArticleCommentsInfo($get = array() ) {
	
		if (empty($get['文章ID'])) {
			return '';
		} else {
			$ar_id = (int) $get['文章ID'];
		}
		
		$sql = "SELECT author,message,time 
				FROM disqus_comment 
				WHERE article_id = {$ar_id}
				ORDER BY cid DESC LIMIT 50";
		$data = $GLOBALS['db']->getAll( $sql );
		
		return $data;	
	}
	
	//note 作者头像
	function getAuthorAvatar( $get ){
		
		$aid = $get['文章ID'];
		
		$sql = "SELECT aut.avatar FROM topic_article AS art
		        LEFT JOIN author AS aut ON art.author_id = aut.aid
		        WHERE art.ar_id = '{$aid}'";	
		$avatar = $GLOBALS['db']->getOne($sql);	
		return $avatar ? $avatar : '';
	}
	
	//note 页面当前地址
	function getPageUrl( $get ){
		$url = $get['url'];
		extract($this->getWebTablesData($get['web_type']));//把数组分解成变量
		$url = url_new_replace($url, $urlType);	
		return $url;	
	}
	
	//得到专题图片
	function getSubjectImage($get = array()) {
		
		if (empty($get['专题ID'])) {
			return '';
		} else {
			$catid = (int) $get['专题ID'];
		}
		
		$pic = $GLOBALS['db']->getOne("SELECT `cat_image` FROM  `category` WHERE `cat_id`= {$catid} ");
		if ($pic) {
			return $pic;
		} else {
			return '';
		}
	}
		
	//得到专题简介
	function getSubjectIntroduction($get = array()) {
		
		if (empty($get['专题ID'])) {
			return '';
		} else {
			$catid = (int) $get['专题ID'];
		}
		
		$desc = $GLOBALS['db']->getOne("SELECT `cat_desc` FROM  `category` WHERE `cat_id`= {$catid} ");
		if ($desc) {
			return $desc;
		} else {
			return '';
		}
	}
		
	//得到专题推荐文章
	function getSubjectRecommendArticleInfo($get = array()) {
		
		if (empty($get['专题ID'])) {
			return '';
		}else {
			$catid = (int) $get['专题ID'];
		}
		
		$web_date = $this->getWebTablesData($get['web_type']);//把数组分解成变量

		$sql = "SELECT tab.MendTime,ar.ar_title,ar.ar_introduction ,ar.ar_image , tab.url 
				FROM topic_article ar 
				LEFT JOIN {$web_date['temArtTable']} tab ON tab.{$web_date['temArtId']} = ar.ar_id 
				WHERE ar.ar_cat_id = {$catid} AND ar.is_recommend = 1 AND ar.is_delete = 0 AND ar.web_type = {$web_date['WebFage']} 
				ORDER BY ar.update_time DESC LIMIT 4 ";

		return array('web_date' => $web_date, 'sql' => $sql);
		
	}
			
	//得到专题热门标签
	function getSubjectHotTagsInfo($get = array()) {
		
		$str ='';	
		$web_date = $this->getWebTablesData($get['web_type']);//把数组分解成变量
		
		$sql = "SELECT c.tag_name,t.url 
				FROM tag c 
				LEFT JOIN {$web_date['temTagTable']} t ON t.{$web_date['temTagId']} = c.tag_id 
				WHERE c.is_hot= 1 AND c.is_delete =0 AND c.tag_web = {$web_date['WebFage']} ";
		
		return array('web_date' => $web_date, 'sql' => $sql);
		
	
	}
		
	//得到专题热门文章列表
	function getSubjectHotArticleListInfo($get = array()) {
		
		$catid = $get['专题ID'];
	
		$web_date = $this->getWebTablesData($get['web_type']);//把数组分解成变量
			
		$sql = "SELECT c.ar_subtitle,t.url 
				FROM topic_article c 
				LEFT JOIN {$web_date['temArtTable']} t ON t.{$web_date['temArtId']} = c.ar_id 
				WHERE c.is_hot = 1 AND c.is_delete = 0 AND c.web_type = {$web_date['WebFage']} AND c.ar_cat_id = {$catid} 
				ORDER BY c.update_time DESC LIMIT 0, 10 ";
		
		return array('web_date' => $web_date, 'sql' => $sql);
	}
	
		
	
	
	//得到专题头部广告
	function getSubjectTopAdInfo($get = array() ) {
		
		$str = '';
		if (empty($get['专题ID'])) {
			return '';
		} else {
			$cat_id = $get['专题ID'];
		} 
		
		extract($this->getAdTablesData($get['web_type'],'subject_top'));//把数组分解成变量
		$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
				FROM ad_delivery, ad, ad_position 
				WHERE ad_delivery.position_id = $positionId AND ad_delivery.cat_id = $cat_id AND ad_delivery.position_type = $positionType 
				AND ad_delivery.ad_web = $adWeb AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1";
						
		$rows = $GLOBALS['db']->getOneRs($sql);
	
		return $rows;
		

	}
		
	//得到专题头部广告
	function getSubjectLeftAdInfo($get = array() ) {
		

		if (empty($get['专题ID'])) {
			return '';
		} else {
			$cat_id = $get['专题ID'];
		}
		
		extract($this->getAdTablesData($get['web_type'],'subject_left'));//把数组分解成变量
		$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
				FROM ad_delivery, ad, ad_position 
				WHERE ad_delivery.position_id =$positionId AND ad_delivery.cat_id = $cat_id AND ad_delivery.position_type = $positionType 
				AND ad_delivery.ad_web = $adWeb AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1 ";		
		$rows = $GLOBALS['db']->getOneRs($sql);
		
		return $rows;
		

	}

	//得到标签热门标签
	function getTagHotsInfo($get = array() ) {
		
		$str = '';	
		$web_date = $this->getWebTablesData($get['web_type']);//把数组分解成变量	
		
		$sql = "SELECT c.tag_name,t.url 
				FROM tag c 
				LEFT JOIN {$web_date['temTagTable']} t ON t.{$web_date['temTagId']} = c.tag_id 
				WHERE c.is_hot = 1 AND c.is_delete =0 AND c.tag_web = {$web_date['WebFage']} ";
		
		return array('web_date' => $web_date, 'sql' => $sql);
	
	}

	
	//得到标签头部广告
	function getTagLeftAdInfo($get = array() ) {
		
		$str = '';
		extract($this->getAdTablesData($get['web_type'],'tag_left'));//把数组分解成变量
		
		$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
				FROM ad_delivery, ad, ad_position 
				WHERE ad_delivery.position_id = $positionId AND ad_delivery.cat_id = 0 AND ad_delivery.position_type = $positionType 
				AND ad_delivery.ad_web = $adWeb AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1 ";
		
		$rows = $GLOBALS['db']->getOneRs($sql);
		
		return $rows;
	}
	
	//得到标签头部广告
	function getTagTopAdInfo($get = array() ) {
		
		$str = '';
		extract($this->getAdTablesData($get['web_type'],'tag_top'));//把数组分解成变量
		
		$sql = "SELECT ad_position.position_size, ad.ad_alt, ad.ad_photo, ad.ad_url,ad_position.position_name, ad.ad_name 
				FROM ad_delivery, ad, ad_position 
				WHERE ad_delivery.position_id = $positionId AND ad_delivery.cat_id = 0 AND ad_delivery.position_type = $positionType 
				AND ad_delivery.ad_web = $adWeb AND ad_position.position_id = ad_delivery.position_id AND ad_delivery.ad_id = ad.ad_id LIMIT 1";		
		$rows = $GLOBALS['db']->getOneRs($sql);
		
		return $rows;
	}
	
	
	
	//得到专题生成分页
	function getSubjectCreatePageInfo($get = array() ) {

		if (empty($get['专题ID'])) {
			return '';
		} else {
			$catid = $get['专题ID'];
		}
		
		
		extract($this->getWebTablesData($get['web_type']));//把数组分解成变量	
		
		//替换模板中的变量为Get主要用于分页
		$template_str = $this->replaceTemplateAndGet($get['tem_style']);
		
		$DirName = dirname($get['url']);
		$dirurl = str_replace('/'.$urlType.'.com/httpdocs/','',$DirName);//专题目录名称
		
		$get['do'] = isset($get['do']) ? $get['do'] : '';
		
		if ( $get['do'] != 'view') {
			
			$dir = DOC_ROOT.'/'.$DirName;
			MakeDir1($dir);
			
			if (!is_dir($dir)) {
				$DirName = DOC_ROOT.'/'.$urlType.'.com/httpdocs';
			}
		}
		
		if (!empty($temArtTable_2)) {
			$sql = " UNION ALL (
					SELECT ar.ar_tag_id,ar.ar_title,ar.ar_introduction ,tab.MendTime ,tab.url ,ar.update_time 
					FROM topic_article ar 
					LEFT JOIN $temArtTable_2 tab ON ar.ar_id = tab.$temArtId_2 
					WHERE ar.ar_cat_id = $catid AND ar.is_delete = 0 AND ar.web_type = $WebFage AND tab.url != '' )	 ";
		}
		
		$sql = "( SELECT ar.ar_tag_id,ar.ar_title,ar.ar_introduction ,tab.MendTime ,tab.url ,ar.update_time 
				FROM topic_article ar 
				LEFT JOIN $temArtTable tab ON ar.ar_id = tab.$temArtId 
				WHERE ar.ar_cat_id = $catid AND ar.is_delete = 0 AND ar.web_type = $WebFage  ) 
				UNION ALL (
				SELECT ar.ar_tag_id,ar.ar_title,ar.ar_introduction ,tab.MendTime ,tab.url ,ar.update_time 
				FROM topic_article ar 
				LEFT JOIN $temArtTable tab ON ar.ar_id = tab.$temArtId 
				WHERE ar.ar_cat_id != $catid AND FIND_IN_SET('$catid',ar.ar_vicecat_id) AND ar.is_delete = 0 AND ar.web_type = $WebFage ) 
				{$sql}
				ORDER BY update_time DESC";

		$res = $GLOBALS['db']->query($sql);
		
		$all = array();
		while ($row = $GLOBALS['db']->fetch_array($res))  {
			
			if (!getURL(DOC_ROOT.$row['url'])) {
				continue;  
			}
			$all[] = $row; 
		}
	
		unset($data, $row);
		/************************* 全部 ********************************************/
		$total = count($all);
		$max_page = ceil($total / 10);
		
		return array('total' => $total, 'max_page' => $max_page, 'dirurl' => $dirurl, 'dir' => $dir,
					 'template_str' => $template_str, 'all' => $all);
	}
	
	//得到标签生成分页
	function getTagCreatePageInfo($get = array() ) {
		
		if (empty($get['标签ID'])) {
			return '';
		} else {
			$tagid = (int) $get['标签ID'];
		}
		
		

		extract($this->getWebTablesData($get['web_type']));//把数组分解成变量	
		//替换模板中的变量为Get主要用于分页
		$template_str = $this->replaceTemplateAndGet($get['tem_style']);
		
		$DirName = dirname($get['url']);
		$dirurl = str_replace('/'.$urlType.'.jp/httpdocs/','',$DirName);//专题目录名称
		
		$get['do'] = isset($get['do']) ? $get['do'] : '';
		if ( $get['do'] != 'view') {
			
			$dir = DOC_ROOT.'/'.$DirName;
			MakeDir1($dir);
			
			if (!is_dir($dir)) {
				$DirName = DOC_ROOT.'/iskysoft.jp/httpdocs';
			}
		}
		
		if (!empty($temArtTable_2)) {
			$sql = " UNION ALL 
					(SELECT ar.ar_tag_id,ar.ar_title,ar.ar_introduction ,tab.MendTime ,tab.url ,ar.update_time 
					FROM topic_article ar 
					LEFT JOIN $temArtTable_2 tab ON ar.ar_id = tab.$temArtId_2 
					WHERE FIND_IN_SET( '$tagid', ar.ar_tag_id ) AND ar.is_delete = 0 AND ar.web_type = $WebFage AND tab.url != ''  ) ";
		}
		
		$sql = "SELECT * FROM ( ( SELECT ar.ar_tag_id,ar.ar_title,ar.ar_introduction ,tab.MendTime ,tab.url,ar.update_time 
				FROM topic_article ar 
				LEFT JOIN $temArtTable tab ON ar.ar_id = tab.$temArtId 
				WHERE FIND_IN_SET( '$tagid', ar.ar_tag_id ) AND ar.is_delete = 0 AND ar.web_type = $WebFage 
				ORDER BY ar.update_time DESC  ) {$sql} ) a  ORDER BY a.update_time DESC ";
		$res = $GLOBALS['db']->query($sql);
		
		$all = array();
		while ($row = $GLOBALS['db']->fetch_array($res))  {
			
			if (!getURL(DOC_ROOT.$row['url'])) {
				continue;  
			}
			$all[] = $row; 
		}
			
		/************************* 全部 ********************************************/
		$total = count($all);
		$max_page = ceil($total / 10);
		
		return array('total' => $total, 'max_page' => $max_page, 'dirurl' => $dirurl, 'dir' => $dir,
					 'template_str' => $template_str, 'all' => $all);

	}
	
	
}
?>